package com.hm.service.api;

import jakarta.servlet.http.HttpServletRequest;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(value = "/MAIN", produces = {"application/json;charset=UTF-8"})
public class TestOpenCV {

    private static final Logger logger = LoggerFactory.getLogger(TestOpenCV.class);

    //测试openCV
    public TestOpenCV() {

    }

    @GetMapping(value = "/test")
    public String doPost(HttpServletRequest request) {
        logger.error("-----------请求进来了-----------");
        String systemProperties = String.valueOf(System.getProperties().get("os.arch"));
        String systemProperties1 = String.valueOf(System.getProperties().get("os.name"));

        //测试图片地址
//        String imgPath = "D:/opencv-test/111.png";



        String imgPath = "/ydcg/111.png";

        //读取图片
        Mat img = Imgcodecs.imread(imgPath);
        //生成灰度图
        Mat gray = new Mat();
        Imgproc.cvtColor(img, gray, Imgproc.COLOR_BGR2GRAY);
        //保存图片
        Imgcodecs.imwrite("/ydcg/result.png", gray);

        return "请求成功--->" + systemProperties + "---------" + systemProperties1;
    }


}
